package com.ruoyi.bnt.controller;

import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bnt.domain.BntWorshipinfo;
import com.ruoyi.bnt.service.IBntWorshipinfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 序乐、回应详情Controller
 * 
 * @author yyj
 * @date 2020-09-24
 */
@Controller
@RequestMapping("/bnt/sundayworship/worshipinfo")
public class BntWorshipinfoController extends BaseController
{
    private String prefix = "bnt/sundayworship/worshipinfo";

    @Autowired
    private IBntWorshipinfoService bntWorshipinfoService;

    @RequiresPermissions("bnt:worshipinfo:view")
    @GetMapping()
    public String worshipinfo()
    {
        return prefix + "/worshipinfo";
    }

    /**
     * 查询序乐、回应详情列表
     */
    @RequiresPermissions("bnt:worshipinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BntWorshipinfo bntWorshipinfo)
    {
        startPage();
        List<BntWorshipinfo> list = bntWorshipinfoService.selectBntWorshipinfoList(bntWorshipinfo);
        return getDataTable(list);
    }

    /**
     * 导出序乐、回应详情列表
     */
    @RequiresPermissions("bnt:worshipinfo:export")
    @Log(title = "序乐、回应详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BntWorshipinfo bntWorshipinfo)
    {
        List<BntWorshipinfo> list = bntWorshipinfoService.selectBntWorshipinfoList(bntWorshipinfo);
        ExcelUtil<BntWorshipinfo> util = new ExcelUtil<BntWorshipinfo>(BntWorshipinfo.class);
        return util.exportExcel(list, "worshipinfo");
    }

    /**
     * 新增序乐、回应详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/add/{parentId}/{infoType}")
    public String add(@PathVariable("parentId") String parentId,@PathVariable("infoType") String infoType, ModelMap mmap)
    {
        mmap.put("parentId", parentId);
        mmap.put("infoType", infoType);
        return prefix + "/add";
    }

    /**
     * 新增保存序乐、回应详情
     */
    @RequiresPermissions("bnt:worshipinfo:add")
    @Log(title = "序乐、回应详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BntWorshipinfo bntWorshipinfo)
    {
        if(bntWorshipinfo.getId() == null || bntWorshipinfo.getId().isEmpty())
            bntWorshipinfo.setId(UUID.randomUUID().toString());
        return toAjax(bntWorshipinfoService.insertBntWorshipinfo(bntWorshipinfo));
    }

    /**
     * 修改序乐、回应详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BntWorshipinfo bntWorshipinfo = bntWorshipinfoService.selectBntWorshipinfoById(id);
        mmap.put("bntWorshipinfo", bntWorshipinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存序乐、回应详情
     */
    @RequiresPermissions("bnt:worshipinfo:edit")
    @Log(title = "序乐、回应详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BntWorshipinfo bntWorshipinfo)
    {
        return toAjax(bntWorshipinfoService.updateBntWorshipinfo(bntWorshipinfo));
    }

    /**
     * 删除序乐、回应详情
     */
    @RequiresPermissions("bnt:worshipinfo:remove")
    @Log(title = "序乐、回应详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bntWorshipinfoService.deleteBntWorshipinfoByIds(ids));
    }
}
